$(document).ready(function() { //一跳转页面就显示初始化信息

	$(".button1").click(function() { //上一页触发事件
		var pagenumbers = $("#button2").val(); //获取当前页数
		//获取分类名字，并向后台传值
		var searchs = $("#name").text();
		if (pagenumbers == 1) {
			alert("亲亲，已经是第一页了哦~")
		} else {

			$.ajax({
				url : "/xiaomi/SearchServlet/PreviousPage",
				type : "post",
				data : {
					"search" : searchs,
					"pagenumber" : pagenumbers
				},
				dataType : "json",
				success : function(data) {
					/*	var state=data.state
						$('#button2').val(state[0]);//总页数*/
					var page = data.state1; //获取总产品数
					var page1 = data.state; //获取总页数
					//给当前页和总页数赋值
					$("#button3").val(page1[0]);
					$("#button2").val(page1[1]);
					var count = page1[0];
					var counts = page.length;
					var div = document.getElementById("div");
					$("#div").empty(); //清楚之前显示，初始化页面

					counts = page.length;

					for (var i = 0; i < counts; i++) {

						var list = page[i];
						//创建一个新的div并将其添加到div中
						var div1 = document.createElement("div");
						div1.className = "div1";

						//在创建一个子类div将其添加到div1中用于存放图片和数据库获取的基本信息
						var div2 = document.createElement("div");
						var div3 = document.createElement("div");
						var div4 = document.createElement("div");
						var div5 = document.createElement("div");
						var p3 = document.createElement("p");
						var p4 = document.createElement("p");
						var p5 = document.createElement("p");

						var a1 = document.createElement("a"); //创建a标签
						a1.className = "a1";
						a1.href = "product/" + list[4];
						a1.onclick = function() {
							tz(this);
						}
						a1.appendChild(div1)
						div.appendChild(a1);
						div2.className = "div2";
						div3.className = "div3";
						div4.className = "div4";
						div5.className = "div5";
						p3.className = "p3";
						p4.className = "p4";
						p5.className = "p5";

						div1.appendChild(div2)
						div1.appendChild(div3)
						div1.appendChild(div4)
						div1.appendChild(div5)
						div3.appendChild(p3)
						div4.appendChild(p4)
						div5.appendChild(p5)

						p3.innerText = list[0];
						p4.innerText = list[2];
						p5.innerText = list[1] + ".00元";

						var img1 = document.createElement("img");
						img1.src = list[3];
						img1.className = "img1";
						div2.appendChild(img1)
					}
				}
			});
		}
	});

	$(".button4").click(function() { //下一页触发事件
		var pagenumberss = $("#button2").val(); //获取当前页数
		var pagenumbers = $("#button3").val(); //总页数
		//获取div值，并向后台传值
		var searchs = $("#name").text();
		//判断是否是最后一页
		if (pagenumberss == pagenumbers) {
			alert("亲亲，已经是最后一页了呢~")
		} else {

			$.ajax({
				url : "/xiaomi/SearchServlet/NextPage",
				type : "post",
				data : {
					"search" : searchs,
					"pagenumber" : pagenumberss
				},
				dataType : "json",
				success : function(data) {
					/*	var state=data.state
						$('#button2').val(state[0]);//总页数*/
					var page = data.state1; //获取总产品数
					var page1 = data.state; //获取总页数

					$("#button3").val(page1[0]);
					$("#button2").val(page1[1]);
					var count = page1[0];
					var counts = page.length;
					var div = document.getElementById("div");
					$("#div").empty(); //清楚之前显示，初始化页面

					counts = page.length;

					for (var i = 0; i < counts; i++) {

						var list = page[i];
						//创建一个新的div并将其添加到div中
						var div1 = document.createElement("div");
						div1.className = "div1";

						//在创建一个子类div将其添加到div1中用于存放图片和数据库获取的基本信息
						var div2 = document.createElement("div");
						var div3 = document.createElement("div");
						var div4 = document.createElement("div");
						var div5 = document.createElement("div");
						var p3 = document.createElement("p");
						var p4 = document.createElement("p");
						var p5 = document.createElement("p");

						var a1 = document.createElement("a"); //创建a标签
						a1.className = "a1";
						a1.href = "product/" + list[4];
						a1.onclick = function() {
							tz(this);
						}
						a1.appendChild(div1)
						div.appendChild(a1);
						div2.className = "div2";
						div3.className = "div3";
						div4.className = "div4";
						div5.className = "div5";
						p3.className = "p3";
						p4.className = "p4";
						p5.className = "p5";

						div1.appendChild(div2)
						div1.appendChild(div3)
						div1.appendChild(div4)
						div1.appendChild(div5)
						div3.appendChild(p3)
						div4.appendChild(p4)
						div5.appendChild(p5)

						p3.innerText = list[0];
						p4.innerText = list[2];
						p5.innerText = list[1] + ".00元";

						var img1 = document.createElement("img");
						img1.src = list[3];
						img1.className = "img1";
						div2.appendChild(img1)
					}
				}
			});
		}
	});

	$(".sousuo").click(function() {
		var divs = document.getElementById("name");
		var searchs = $("#search").val();

		divs.innerHTML = searchs + "相关产品";

		$.ajax({
			url : "/xiaomi/SearchServlet/HomePage",
			type : "post",
			data : {
				"search" : searchs
			},
			dataType : "json",
			success : function(data) {
				/*	var state=data.state
					$('#button2').val(state[0]);//总页数*/
				var page = data.state1; //获取总产品数
				var page1 = data.state; //获取总页数
				//			pagess.val();
				//			pagess.value=page1[1];
				if (page.length == 0) {
					alert("亲亲，没有查询到你需要的产品呢~~~")
				}
				;
				$("#button3").val(page1[0]);
				$("#button2").val(1);

				var count = page1[0];
				var counts;
				var div = document.getElementById("div");
				var divs = document.getElementById("name");
				$("#div").empty();
				if (count > 1) {
					var counts = 10;
				} else {
					counts = page.length;
				}
				for (var i = 0; i < counts; i++) {

					var list = page[i];
					//创建一个新的div并将其添加到div中
					var div1 = document.createElement("div");
					div1.className = "div1";

					//在创建一个子类div将其添加到div1中用于存放图片和数据库获取的基本信息
					var div2 = document.createElement("div");
					var div3 = document.createElement("div");
					var div4 = document.createElement("div");
					var div5 = document.createElement("div");
					var p3 = document.createElement("p");
					var p4 = document.createElement("p");
					var p5 = document.createElement("p");

					var a1 = document.createElement("a"); //创建a标签
					a1.className = "a1";
					//				 	a1.href="product/"+list[4];
					a1.href = "http://localhost:8080/xiaomi/product/" + list[4];
					a1.appendChild(div1)
					div.appendChild(a1);
					div2.className = "div2";
					div3.className = "div3";
					div4.className = "div4";
					div5.className = "div5";
					p3.className = "p3";
					p4.className = "p4";
					p5.className = "p5";

					div1.appendChild(div2)
					div1.appendChild(div3)
					div1.appendChild(div4)
					div1.appendChild(div5)
					div3.appendChild(p3)
					div4.appendChild(p4)
					div5.appendChild(p5)

					p3.innerText = list[0];
					p4.innerText = list[2];
					p5.innerText = list[1] + ".00元";

					var img1 = document.createElement("img");
					img1.src = list[3];
					img1.className = "img1";
					div2.appendChild(img1)
				}
			}
		});
	});
	$("#mi-21").click(function() {
		var divs = document.getElementById("name");
		var pagenumberss = $("#button2").val(); //获取当前页数
		divs.innerHTML = "小米手机";
		var codel = $("#mi-2").attr("id");
		var code = codel.split("-")[1];

		$.ajax({
			url : "/xiaomi/category/pageAndTotalpages",
			type : "post",
			data : {
				"page" : code,
				"pagenumber" : pagenumberss
			},
			dataType : "json",
			success : function(data) {
				var page1 = data.state;
				$("#button3").val(page1[0]);
				var page = data.state1;
				console.info(page);
				var div = document.getElementById("div");
				$("#div").empty();
				for (var i = 0; i < page.length; i++) {

					var list = page[i];
					//创建一个新的div并将其添加到div中
					var div1 = document.createElement("div");
					div1.className = "div1";

					//在创建一个子类div将其添加到div1中用于存放图片和数据库获取的基本信息
					var div2 = document.createElement("div");
					var div3 = document.createElement("div");
					var div4 = document.createElement("div");
					var div5 = document.createElement("div");
					var p3 = document.createElement("p");
					var p4 = document.createElement("p");
					var p5 = document.createElement("p");

					var a1 = document.createElement("a"); //创建a标签
					a1.className = "a1";
					a1.href = "product/" + list[4];
					a1.appendChild(div1)
					div.appendChild(a1);
					div2.className = "div2";
					div3.className = "div3";
					div4.className = "div4";
					div5.className = "div5";
					p3.className = "p3";
					p4.className = "p4";
					p5.className = "p5";

					div1.appendChild(div2)
					div1.appendChild(div3)
					div1.appendChild(div4)
					div1.appendChild(div5)
					div3.appendChild(p3)
					div4.appendChild(p4)
					div5.appendChild(p5)

					p3.innerText = list[0];
					p4.innerText = list[2];
					p5.innerText = list[1] + ".00元";

					var img1 = document.createElement("img");
					img1.src = list[3];
					img1.className = "img1";
					div2.appendChild(img1)
				}
			}
		});
	});
	$("#mi-2").ready(function() {
		var pagenumberss = $("#button2").val(); //获取当前页数
		var codel = $("#mi-2").attr("id");
		var code = codel.split("-")[1];
		$.ajax({
			url : "/xiaomi/category/pageAndTotalpages",
			type : "post",
			data : {
				"page" : code,
				"pagenumber" : pagenumberss
			},
			dataType : "json",
			success : function(data) {
				var page1 = data.state;
				$("#button3").val(page1[0]);
				var page = data.state1;
				console.info(page);
				var div = document.getElementById("div");
				$("#div").empty();
				for (var i = 0; i < page.length; i++) {

					var list = page[i];
					//创建一个新的div并将其添加到div中
					var div1 = document.createElement("div");
					div1.className = "div1";

					//在创建一个子类div将其添加到div1中用于存放图片和数据库获取的基本信息
					var div2 = document.createElement("div");
					var div3 = document.createElement("div");
					var div4 = document.createElement("div");
					var div5 = document.createElement("div");
					var p3 = document.createElement("p");
					var p4 = document.createElement("p");
					var p5 = document.createElement("p");

					var a1 = document.createElement("a"); //创建a标签
					a1.className = "a1";
					a1.href = "product/" + list[4];
					a1.appendChild(div1)
					div.appendChild(a1);
					div2.className = "div2";
					div3.className = "div3";
					div4.className = "div4";
					div5.className = "div5";
					p3.className = "p3";
					p4.className = "p4";
					p5.className = "p5";

					div1.appendChild(div2)
					div1.appendChild(div3)
					div1.appendChild(div4)
					div1.appendChild(div5)
					div3.appendChild(p3)
					div4.appendChild(p4)
					div5.appendChild(p5)

					p3.innerText = list[0];
					p4.innerText = list[2];
					p5.innerText = list[1] + ".00元";

					var img1 = document.createElement("img");
					img1.src = list[3];
					img1.className = "img1";
					div2.appendChild(img1)
				}
			}
		});
	});
	$("#mi-3").click(function() {
		var codel = $("#mi-3").attr("id");
		var code = codel.split("-")[1];
		var divs = document.getElementById("name");
		divs.innerHTML = "路由器";
		$.ajax({
			url : "/xiaomi/category/pageAndTotalpages",
			type : "post",
			data : {
				"page" : code
			},
			dataType : "json",
			success : function(data) {
				var page1 = data.state;
				$("#button3").val(page1[0]);
				var page = data.state1;
				console.info(page);
				var div = document.getElementById("div");
				$("#div").empty();
				for (var i = 0; i < page.length; i++) {

					var list = page[i];
					//创建一个新的div并将其添加到div中
					var div1 = document.createElement("div");
					div1.className = "div1";

					//在创建一个子类div将其添加到div1中用于存放图片和数据库获取的基本信息
					var div2 = document.createElement("div");
					var div3 = document.createElement("div");
					var div4 = document.createElement("div");
					var div5 = document.createElement("div");
					var p3 = document.createElement("p");
					var p4 = document.createElement("p");
					var p5 = document.createElement("p");

					var a1 = document.createElement("a"); //创建a标签
					a1.className = "a1";
					a1.href = "product/" + list[4];

					a1.appendChild(div1)
					div.appendChild(a1);
					div2.className = "div2";
					div3.className = "div3";
					div4.className = "div4";
					div5.className = "div5";
					p3.className = "p3";
					p4.className = "p4";
					p5.className = "p5";

					div1.appendChild(div2)
					div1.appendChild(div3)
					div1.appendChild(div4)
					div1.appendChild(div5)
					div3.appendChild(p3)
					div4.appendChild(p4)
					div5.appendChild(p5)

					p3.innerText = list[0];
					p4.innerText = list[2];
					p5.innerText = list[1] + ".00元";

					var img1 = document.createElement("img");
					img1.src = list[3];
					img1.className = "img1";
					div2.appendChild(img1)
				}
			}
		});
	});
	$("#mi-4").click(function() {
		var pagenumberss = $("#button2").val(); //获取当前页数
		var codel = $("#mi-4").attr("id");
		var code = codel.split("-")[1];
		var divname = document.getElementById("name");
		var divs = document.getElementById("name");
		divs.innerHTML = "平板·笔记本";

		$.ajax({
			url : "/xiaomi/category/pageAndTotalpages",
			type : "post",
			data : {
				"page" : code,
				"pagenumber" : pagenumberss
			},
			dataType : "json",
			success : function(data) {
				var page1 = data.state;
				$("#button3").val(page1[0]);
				var page = data.state1;
				console.info(page);
				var div = document.getElementById("div");
				$("#div").empty();
				for (var i = 0; i < page.length; i++) {

					var list = page[i];
					//创建一个新的div并将其添加到div中
					var div1 = document.createElement("div");
					div1.className = "div1";

					//在创建一个子类div将其添加到div1中用于存放图片和数据库获取的基本信息
					var div2 = document.createElement("div");
					var div3 = document.createElement("div");
					var div4 = document.createElement("div");
					var div5 = document.createElement("div");
					var p3 = document.createElement("p");
					var p4 = document.createElement("p");
					var p5 = document.createElement("p");

					var a1 = document.createElement("a"); //创建a标签
					a1.className = "a1";
					a1.href = "product/" + list[4];
					a1.onclick = function() {
						tz(this);
					}
					a1.appendChild(div1)
					div.appendChild(a1);
					div2.className = "div2";
					div3.className = "div3";
					div4.className = "div4";
					div5.className = "div5";
					p3.className = "p3";
					p4.className = "p4";
					p5.className = "p5";

					div1.appendChild(div2)
					div1.appendChild(div3)
					div1.appendChild(div4)
					div1.appendChild(div5)
					div3.appendChild(p3)
					div4.appendChild(p4)
					div5.appendChild(p5)

					p3.innerText = list[0];
					p4.innerText = list[2];
					p5.innerText = list[1] + ".00元";

					var img1 = document.createElement("img");
					img1.src = list[3];
					img1.className = "img1";
					div2.appendChild(img1)
				}
			}
		});
	});
	$("#mi-9").click(function() {
		var pagenumberss = $("#button2").val(); //获取当前页数

		var codel = $("#mi-9").attr("id");
		var code = codel.split("-")[1];
		var divs = document.getElementById("name");
		divs.innerHTML = "盒子·影音";

		$.ajax({
			url : "/xiaomi/category/pageAndTotalpages",
			type : "post",
			data : {
				"page" : code,
				"pagenumber" : pagenumberss
			},
			dataType : "json",
			success : function(data) {
				var page1 = data.state;
				$("#button3").val(page1[0]);
				var page = data.state1;
				console.info(page);
				var div = document.getElementById("div");
				$("#div").empty();
				for (var i = 0; i < page.length; i++) {

					var list = page[i];
					//创建一个新的div并将其添加到div中
					var div1 = document.createElement("div");
					div1.className = "div1";

					//在创建一个子类div将其添加到div1中用于存放图片和数据库获取的基本信息
					var div2 = document.createElement("div");
					var div3 = document.createElement("div");
					var div4 = document.createElement("div");
					var div5 = document.createElement("div");
					var p3 = document.createElement("p");
					var p4 = document.createElement("p");
					var p5 = document.createElement("p");

					var a1 = document.createElement("a"); //创建a标签
					a1.className = "a1";
					a1.href = "product/" + list[4];
					a1.onclick = function() {
						tz(this);
					}
					a1.appendChild(div1)
					div.appendChild(a1);
					div2.className = "div2";
					div3.className = "div3";
					div4.className = "div4";
					div5.className = "div5";
					p3.className = "p3";
					p4.className = "p4";
					p5.className = "p5";

					div1.appendChild(div2)
					div1.appendChild(div3)
					div1.appendChild(div4)
					div1.appendChild(div5)
					div3.appendChild(p3)
					div4.appendChild(p4)
					div5.appendChild(p5)

					p3.innerText = list[0];
					p4.innerText = list[2];
					p5.innerText = list[1] + ".00元";

					var img1 = document.createElement("img");
					img1.src = list[3];
					img1.className = "img1";
					div2.appendChild(img1)
				}
			}
		});
	});

	$("#mi-6").click(function() {
		var pagenumberss = $("#button2").val(); //获取当前页数
		var codel = $("#mi-6").attr("id");
		var code = codel.split("-")[1];
		var divs = document.getElementById("name");
		divs.innerHTML = "电视";
		$.ajax({
			url : "/xiaomi/category/pageAndTotalpages",
			type : "post",
			data : {
				"page" : code,
				"pagenumber" : pagenumberss
			},
			dataType : "json",
			success : function(data) {
				var page1 = data.state;
				$("#button3").val(page1[0]);
				var page = data.state1;
				console.info(page);
				var div = document.getElementById("div");
				$("#div").empty();
				for (var i = 0; i < page.length; i++) {

					var list = page[i];
					//创建一个新的div并将其添加到div中
					var div1 = document.createElement("div");
					div1.className = "div1";

					//在创建一个子类div将其添加到div1中用于存放图片和数据库获取的基本信息
					var div2 = document.createElement("div");
					var div3 = document.createElement("div");
					var div4 = document.createElement("div");
					var div5 = document.createElement("div");
					var p3 = document.createElement("p");
					var p4 = document.createElement("p");
					var p5 = document.createElement("p");

					var a1 = document.createElement("a"); //创建a标签
					a1.className = "a1";
					a1.href = "product/" + list[4];
					a1.onclick = function() {
						tz(this);
					}
					a1.appendChild(div1)
					div.appendChild(a1);
					div2.className = "div2";
					div3.className = "div3";
					div4.className = "div4";
					div5.className = "div5";
					p3.className = "p3";
					p4.className = "p4";
					p5.className = "p5";

					div1.appendChild(div2)
					div1.appendChild(div3)
					div1.appendChild(div4)
					div1.appendChild(div5)
					div3.appendChild(p3)
					div4.appendChild(p4)
					div5.appendChild(p5)

					p3.innerText = list[0];
					p4.innerText = list[2];
					p5.innerText = list[1] + ".00元";

					var img1 = document.createElement("img");
					img1.src = list[3];
					img1.className = "img1";
					div2.appendChild(img1)
				}
			}
		});
	});
	$("#mi-5").click(function() {
		var pagenumberss = $("#button2").val(); //获取当前页数
		var codel = $("#mi-5").attr("id");
		var code = codel.split("-")[1];
		var divs = document.getElementById("name");

		divs.innerHTML = "智能硬件";
		$.ajax({
			url : "/xiaomi/category/pageAndTotalpages",
			type : "post",
			data : {
				"page" : code,
				"pagenumber" : pagenumberss
			},
			dataType : "json",
			success : function(data) {
				var page1 = data.state;
				$("#button3").val(page1[0]);
				var page = data.state1;

				var div = document.getElementById("div");
				$("#div").empty();
				for (var i = 0; i < page.length; i++) {

					var list = page[i];
					//创建一个新的div并将其添加到div中
					var div1 = document.createElement("div");
					div1.className = "div1";

					//在创建一个子类div将其添加到div1中用于存放图片和数据库获取的基本信息
					var div2 = document.createElement("div");
					var div3 = document.createElement("div");
					var div4 = document.createElement("div");
					var div5 = document.createElement("div");
					var p3 = document.createElement("p");
					var p4 = document.createElement("p");
					var p5 = document.createElement("p");

					var a1 = document.createElement("a"); //创建a标签
					a1.className = "a1";
					a1.href = "product/" + list[4];
					a1.onclick = function() {
						tz(this);
					}
					a1.appendChild(div1)
					div.appendChild(a1);
					div2.className = "div2";
					div2.idNmae = list[4];
					div3.className = "div3";
					div4.className = "div4";
					div5.className = "div5";
					p3.className = "p3";
					p4.className = "p4";
					p5.className = "p5";

					div1.appendChild(div2)
					div1.appendChild(div3)
					div1.appendChild(div4)
					div1.appendChild(div5)
					div3.appendChild(p3)
					div4.appendChild(p4)
					div5.appendChild(p5)

					p3.innerText = list[0];
					p4.innerText = list[2];
					p5.innerText = list[1] + ".00元";

					var img1 = document.createElement("img");
					img1.src = list[3];
					img1.className = "img1";
					div2.appendChild(img1)
				}
			}
		});
	});
	$()
	
})